# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# Author     ：skyTree
# version    ：python 3.11
# Description：用户操作的schemas
"""
from datetime import datetime
from pydantic import BaseModel, Field
from typing import Union, List

from .base import DetailBaseResp, PageResponse, BaseResponse


class RoleSchema(BaseModel):
    id: int
    name: str
    desc: Union[str, None] = None


class UserCreateSchema(BaseModel):
    name: str
    password: str
    confirm_password: str
    nick_name: Union[str, None] = None
    phone: Union[str, None] = None
    email: Union[str, None] = None
    role: Union[int, None] = None


class UserEditSchema(BaseModel):
    id: int
    nick_name: Union[str, None] = None
    phone: Union[str, None] = None
    email: Union[str, None] = None
    role: Union[int, None] = None


class UserOutSchema(BaseModel):
    id: int
    name: str
    nick_name: Union[str, None] = None
    phone: Union[str, None] = None
    email: Union[str, None] = None
    role: Union[RoleSchema, List, None] = None
    create_time: datetime
    update_time: datetime
    permissionsList: List[str] = []


class LoginSchema(BaseModel):
    username: str = Field(min_length=3, max_length=10, description="用户名")
    password: str = Field(min_length=6, max_length=20, description="密码")


class UserResponseSchema(BaseResponse):
    data: UserOutSchema


class TokenOutSchema(BaseModel):
    token: str
    user: UserOutSchema


class UserTokenSchema(DetailBaseResp):
    data: TokenOutSchema


class UserListOutSchema(DetailBaseResp):
    data: PageResponse
